<?php

namespace api\models;

use Yii;
use yii\web\Linkable;
use yii\web\Link;
use yii\helpers\Url;

class News extends \common\models\News implements Linkable
{
//修改时不导致你的字段修改（保持后端API兼容性）
  public function fields()
  {
//    $fields = parent::fields();
//    // 删除一些包含敏感信息的字段
//    unset($fields['auth_key'], $fields['password_hash'], $fields['password_reset_token']);
//    return $fields;

    return [
      // 字段名和属性名相同
      'id',
      // 字段名为"email", 对应的属性名为"email_address"
      'title' => 'title',
      // 字段名为"name", 值由一个PHP回调函数定义
      'name' => function ($model) {
        return $model->content . ' ' . $model->created_at;
      },
      //'profile'=> function ($model) { return ['id'=>1,'name'=>'aaaa'] }
    ];
  }
  public $profile;
  public function extraFields()
  {
    return ['profile'];
  }

  public function getLinks()
  {
    return [
      Link::REL_SELF => Url::to(['news/view', 'id' => $this->id], true),
    ];
  }
}
